package com.zmcc.service.impl;

import com.google.gson.Gson;
import com.zmcc.entity.MidAXBTemplate;
import com.zmcc.entity.MidAXTemplate;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.service.IMidRequest;

import java.util.HashMap;
import java.util.Map;

public class MidRequestCommercial implements IMidRequest {
    private final static String url = "https://dev.cmccopen.cn/api";

    private static MidRequestCommercial midRequestCommercial;

    public static MidRequestCommercial getInstance() {
        if (midRequestCommercial == null) {
            midRequestCommercial = new MidRequestCommercial();
        }
        return midRequestCommercial;
    }

    @Override
    public CommonRequest getMidAxbBindRequest(MidAXBTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/midb" +"/bind");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getMidAxbUnBindRequest(String bindId) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/midb" +"/unbind");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("bindId",bindId);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getMidAxbDelayRequest(String bindId, String delta) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/midb" +"/delay");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("bindId",bindId);
        bodyMap.put("delta",delta);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getMidAxbBlacklistRequest(String blackList, String opType) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/midb" +"/blacklist");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("blackList",blackList);
        bodyMap.put("opType",opType);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getMidAxBindRequest(MidAXTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/mid" +"/bind");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getMidAxUnBindRequest(String bindId, int coolDown) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/mid" +"/unbind");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("bindId",bindId);
        bodyMap.put("coolDown",coolDown);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getMidAxDelayRequest(String bindId, String delta) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/mid" +"/delay");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("bindId",bindId);
        bodyMap.put("delta",delta);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getMidAxBlacklistRequest(String blackList, String opType) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/mid" +"/blacklist");
        Map<String, Object> bodyMap = new HashMap();
        bodyMap.put("blackList",blackList);
        bodyMap.put("opType",opType);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

}
